<template>
    <view class="content">
        <button type="primary" plain="true" lang="en" open-type="getUserInfo" @getuserinfo="getuserinfo">登录</button>
	</view>

</template>

<script lang="ts">
    import Vue from 'vue';
    import {mapState, mapGetters} from 'vuex';

    export default Vue.extend({
        data() {
            return {}
        },
        onLoad() {

        },
        computed: {},
        methods: {
            getuserinfo(res) {
                // 模拟一个用户id
								let userId = this.randomNum(10000, 99999);
								let userInfo = res.detail.userInfo
								uni.setStorageSync('userId', userId);
								uni.setStorageSync('userInfo', userInfo);
								if (userInfo && userId) {
									this.$store.dispatch('initTim', {}).then((res) =>{
										uni.redirectTo({
				              url: '/pages/index/index'
				            });
									})
								}
								// 登录失败

            },
						// 该函数无多大意义就是生成一下用户id
		        randomNum (minNum, maxNum) {
		            switch (arguments.length) {
		                case 1:
		                    return parseInt(Math.random() * minNum + 1, 10);
		                    break;
		                case 2:
		                    return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
		                    break;
		                default:
		                    return 0;
		                    break;
		            }
		        }
        }
    });
</script>

<style>
    .content {
        text-align: center;
        height: 400 upx;
    }

    .logo {
        height: 200 upx;
        width: 200 upx;
        margin-top: 200 upx;
    }

    .title {
        font-size: 36 upx;
        color: #8f8f94;
    }
</style>
